Translate _d_arrayappend{T,cTX} to templates#2632
Conversation
|
This uses |
src/object.d
Outdated
| // These are needed to fake the safety level to `@safe pure nothrow`. | ||
| // Without this code will break as these hooks where previously exported | ||
| // as having this safety level. | ||
| T[] _d_arrayappendT(T)(ref T[] x, scope T[] y) @trusted |
There was a problem hiding this comment.
Is the @trusted on this declaration redundant? It seems that since the call to _d_arrayappendT_ is wrapped @trusted. the @trusted attribute at entry point is not necessary.
There was a problem hiding this comment.
Do we need to return T[]?
For chaining?
There was a problem hiding this comment.
It returns T[] because the original hook returned void[]. I also just found a problem with the current implementation in dmd:
int[] arr;
((arr ~= [1,2,3]) ~= 4) ~= 5;This crashes in the backend for dmd (https://run.dlang.io/is/UZAIuX), while working as expected in ldc (arr == [1, 2, 3, 4, 5]).
So I should probably change this to return a ref T[], to match ldc's behavior.
I think I still need @trusted for the outer functions as I get this error if I remove @trusted on _d_arrayappendcT.
std/uni.d(6165): Error: @safe function std.uni.Stack!(InversionList!(GcPolicy)).Stack.push cannot call @system function object._d_arrayappendcT!(InversionList!(GcPolicy))._d_arrayappendcT
Sorry, I misunderstood the question. I would prefer to keep the changes in this PR so we don't have two different implementations doing the same thing. |
The really strange thing here and the reason this fails to link is that
Also strange The |
I’ve run into this before. The C bindings are not being compiled. So the few macros that have been translated to functions are not compiled and causes linker errors. |
Perhaps compiling with |
jacob-carlborg
left a comment
There was a problem hiding this comment.
Can all the new symbols be private and have the compiler bypass the protection?
I think I will remove that commit, and then apply it later when I do a clean-up PR. |
src/object.d
Outdated
|
|
||
| T[] _d_arrayappendcTXTrace(T)(string file, int line, string funcname, ref T[] px, size_t n) @trusted pure | ||
| { | ||
| import rt.profilegc : accumulate; |
There was a problem hiding this comment.
Note that the implementation of the tracing functions has changed recently, see #2607
I wouldn't mind if the trace-functions are left unmodified, it's a half-baked feature anyway and slows down execution in accumulate.
There was a problem hiding this comment.
The problem is that the new entrypoints for the hooks are templates, so I need to manually write a trace entrypoint. It also need to be in object.d so the compiler can reference it from the lowering code. https://github.com/dlang/dmd/pull/9982/files#diff-0c1aa1ff99402eb87e11cc3fa1b80da0
cec2e74 to
b0ea4b9
Compare
|
I've updated the code according to the comments, but the unittest will still fail. This time because when I changed the compiler to rewrite I intent on fixing this as soon as possible. |
3581270 to
b572d12
Compare
|
Update: |
1d7120f to
1592adb
Compare
1592adb to
e1c1e2b
Compare
src/object.d
Outdated
| /// See $(REF capacity, rt,array,capacity) | ||
| public import rt.array.capacity: capacity; | ||
|
|
||
| /// See $(REF _d_arrayappendT, rt,array,append) and $(REF _d_arrayappendTTrace, rt,array,append) |
There was a problem hiding this comment.
You actually don't need to document these, because they are not called directly by the user. capacity.d has functions that are called directly by the user, so it is an exception. I'd like to add a version(Core_Doc) block to filter out the runtime hooks so they don't appear in the documentation. I wouldn't mind if you added that version block to this PR, but I understand if you want to keep the scope of this PR down. I intend to add it myself after my pending druntime PRs are merged.
There was a problem hiding this comment.
Okey, thanks.
It think it is better to do the version(Core_Doc) in a separate PR.
10bb660 to
530bd7e
Compare
530bd7e to
238a29a
Compare
|
Thanks for your pull request and interest in making D better, @Vild! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + druntime#2632" |
src/rt/array/append.d
Outdated
| // release. It also cannot be core.internal.externDFunc'd because that causes recursive template instantiation. | ||
|
|
||
| /// See $(REF _d_arrayappendcTX, rt,lifetime,_d_arrayappendcTX) | ||
| private extern (C) byte[] _d_arrayappendcTX(const TypeInfo ti, ref byte[] px, size_t n); |
There was a problem hiding this comment.
I think I commented about this before, but I can't find my comment now. I think this can be imported instead of being declared as an extern
There was a problem hiding this comment.
I don't think it can because it will be instantiated inside the template and rt.lifetime not part of a dmd installation.
There was a problem hiding this comment.
Ok, it looks like we'll eventually need to change the DMD installation to make all this templating of druntime work, but that is out of scope of the task at hand.
src/rt/array/append.d
Outdated
| // This template will be instanciated even in betterC due to the lowering code. | ||
| // So we need to disallow the calling of this function if that happens. | ||
| version (D_BetterC) | ||
| assert(0, "_d_arrayappendcTX does not support betterC!"); |
There was a problem hiding this comment.
What happens if you don't specifically have this check. Won't the -betterC build just emit a generic error about not supporting TypeInfo?
There was a problem hiding this comment.
Also, if you do choose to keep this message, I don't think it should specifically mention _d_arrayappendcTX because that never appears in the user's code. I suggest something worded more as "betterC does not support appending arrays because it requires runtime support".
And I think that it can be a static assert at the beginning of the _d_arrayappendcTX template so the user gets a compile-time assertion failure instead of a runtime assertion failure.
There was a problem hiding this comment.
So without this check test19561.d will fail with Error: TypeInfo cannot be used with -betterC, even if that expression will be intercepted by the CTFE later.
and it cannot be a static assert because that breaks the lowering code.
import/rt/array/append.d(121): Error: static assert: "_d_arrayappendcTX does not support betterC!"
import/rt/array/append.d(35): instantiated from here: _d_arrayappendcTX!(immutable(char))
import/core/internal/arrayop.d(320): instantiated from here: _d_arrayappendT!(immutable(char))
import/core/internal/arrayop.d(45): instantiated from here: initScalarVecs!(int, "+=")
import/object.d(3696): instantiated from here: arrayOp!(int[], int, "+=")
238a29a to
56c4ad0
Compare
|
So as it seems we can't avoid the Code LGTM. |
56c4ad0 to
595c17f
Compare
I did the last few fixes and I'm happy with it for now. |
595c17f to
ddb55e7
Compare
|
This PR needs to implements the same fixes as in #2667, before it is ready to be merged |
|
@Vild Can you rebase this to get rid of the conflicts and see if we can get this in? |
Done. |
…itNoThrow` Signed-off-by: Dan Printzell <xwildn00bx@gmail.com>
Signed-off-by: Dan Printzell <xwildn00bx@gmail.com>
Signed-off-by: Dan Printzell <xwildn00bx@gmail.com>
ddb55e7 to
cd53555
Compare
|
This PR is ready to be merged |
dmd PR: dlang/dmd#9982
This PR adds templated version of
_d_arrayappend{T,cTX}.Notes
_d_arrayappend{c,w}dwere not translated because they did not use TypeInfo in their interface. But they were changed to use the new hooks.